﻿//google Translate api
function googleTranslateElementInit() {
    new google.translate.TranslateElement({ pageLanguage: 'ar', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element');
}

//Redirect
function Redirect(url,millesecons) {
    window.setTimeout(function () {
        window.location.href = url;
    }, millesecons);
}

//get radwindow
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;

    else if (window.frameElement.radWindow)
        oWindow = window.frameElement.radWindow;
    return oWindow;
}


//start silverLightScan
function startSilverLightScan(button, id, port) {

    try {
        var silverLightControl = document.getElementById('scanADocumentObject');
        silverLightControl.content.Page.startScan(button, id, port);
    }
    catch (ex) {
        setTimeout(function () {
            startSilverLightScan(button, id, port);
        }, 500);
    }
}

//finish silverlight
function mySilverLightDoPostBack(name, params) {
    __doPostBack(name, params);
}

//do postback for export buttons in AdvancedRadGrid
function mngRequestStarted(ajaxManager, eventArgs) {
    if ((eventArgs.EventTarget.indexOf("ExportToExcelButton") != -1) || (eventArgs.EventTarget.indexOf("ExportToWordButton") != -1) || (eventArgs.EventTarget.indexOf("ExportToPdfButton") != -1)) {
        eventArgs.EnableAjax = false;
    }
}


function mngResponseEnded(ajaxManager, eventArgs) {


    //initialize font
    $('#middle').find("*").css('font-family', 'Tahoma, Geneva, sans-serif');
    $('#middle').find("*").css('font-size', '14px');
    //set font after ajax reponse
    if ($.cookie('family')) {
        $('#middle').find("*").css('font-family', $.cookie('family'));
        $('#inputFont').val($('#inputFont').val() + ' ' + $.cookie('family'));
    }
    if ($.cookie('weight')) {
        $('#middle').find("*").css('font-weight', $.cookie('weight'));
        $('#inputFont').val($('#inputFont').val() + ' ' + $.cookie('weight'));
    }
    if ($.cookie('style')) {
        $('#middle').find("*").css('font-style', $.cookie('style'));
        $('#inputFont').val($('#inputFont').val() + ' ' + $.cookie('style'));
    }
    if ($.cookie('size')) {
        $('#middle').find("*").css('font-size', $.cookie('size'));
        $('#inputFont').val($('#inputFont').val() + ' ' + $.cookie('size'));
    }

}



//document ready
$(document).ready(
    function () {

        //calculate min height for page
        $('#middle').css('min-height', ($(window).outerHeight() - $('#header').outerHeight() - $('#footer').outerHeight()));


        //initialize font
        $('#middle').find("*").css('font-family', 'Tahoma, Geneva, sans-serif');
        $('#middle').find("*").css('font-size', '14px');
        if (typeof $('#inputFont') != 'undefined') {
            $('#inputFont').fontpicker({ showNoneButton: false, regional: 'ar' });
            //set font and cookie on change 
            $('#inputFont').change(function (event) {
                var res = $('#inputFont').val().replace('font-weight:400;', '').replace('letter-spacing:0;', '');
                var family = res.substr(res.indexOf('font-family')).replace('font-family:', '');
                family = family.substring(0, family.indexOf(';'));
                family = (family == '' ? 'Tahoma, Geneva, sans-serif' : family);
                var weight = res.substr(res.indexOf('font-weight')).replace('font-weight:', '');
                weight = weight.substring(0, weight.indexOf(';'));
                weight = (weight == '' ? 'normal' : weight);
                var style = res.substr(res.indexOf('font-style')).replace('font-style:', '');
                style = style.substring(0, style.indexOf(';'));
                style = (style == '' ? 'normal' : style);
                var size = res.substr(res.indexOf('font-size')).replace('font-size:', '');
                size = size.substring(0, size.indexOf(';'));
                size = (size == '' ? '14px' : size);

                $('#middle').find("*").css('font-family', family);
                $.cookie('family', family, { expires: 365, path: '/' });

                $('#middle').find("*").css('font-weight', weight);
                $.cookie('weight', weight, { expires: 365, path: '/' });

                $('#middle').find("*").css('font-style', style);
                $.cookie('style', style, { expires: 365, path: '/' });

                $('#middle').find("*").css('font-size', size);
                $.cookie('size', size, { expires: 365, path: '/' });

                $('#inputFont').val(family + ' ' + size + ' ' + weight + ' ' + style);
            });
        }


        //initialize background color
        if (typeof $('#divColorPicker') != 'undefined') {
            $('#divColorPicker').ColorPicker({
                //remove form decorated and set color of picker 
                onShow: function () {
                    $('.colorpicker .rfdDecorated').removeClass('rfdRoundedCorners rfdDecorated');
                    $('#divColorPicker').ColorPickerSetColor('#E4EFF7');
                },
                //set color and cookies on change 
                onChange: function (hsb, hex, rgb) {
                    $('#mainDiv').css('background-color', '#' + hex);
                    $('#header').css('background-color', '#' + hex);
                    $('#divColorPicker').css('background-color', '#' + hex);
                    $.cookie('backgroundColor', hex, { expires: 365, path: '/' });
                },
            });
        }

        //set elements from cookies
        if ($.cookie('backgroundColor')) {
            $('#mainDiv').css('background-color', '#' + $.cookie('backgroundColor'));
            $('#header').css('background-color', '#' + $.cookie('backgroundColor'));
            $('#divColorPicker').css('background-color', '#' + $.cookie('backgroundColor'));
            $('#divColorPicker').ColorPickerSetColor('#' + $.cookie('backgroundColor'));
        }
        if ($.cookie('family')) {
            $('#middle').find("*").css('font-family', $.cookie('family'));
            $('#inputFont').val($('#inputFont').val() + ' ' + $.cookie('family'));
        }
        if ($.cookie('weight')) {
            $('#middle').find("*").css('font-weight', $.cookie('weight'));
            $('#inputFont').val($('#inputFont').val() + ' ' + $.cookie('weight'));
        }
        if ($.cookie('style')) {
            $('#middle').find("*").css('font-style', $.cookie('style'));
            $('#inputFont').val($('#inputFont').val() + ' ' + $.cookie('style'));
        }
        if ($.cookie('size')) {
            $('#middle').find("*").css('font-size', $.cookie('size'));
            $('#inputFont').val($('#inputFont').val() + ' ' + $.cookie('size'));
        }
    });


